<?php
namespace App\Services;


class WechatArticleService{

    public function getWechatArticle(int $page,int $page_size){
        $offset = ($page-1)*$page_size;
        $officialAccount = \EasyWeChat::officialAccount(); // 公众号 订阅号
        //微信订阅号文章列表做
        $sub_wx_article =  $officialAccount->material->list("news", $offset, $page_size);

        $sub_wx_article_list = [];
        if ($sub_wx_article['item_count']>0){
            foreach ($sub_wx_article['item'] as $key=>$val){
                foreach ($val['content']['news_item'] as $k=>$v){
                    $sub_wx_article_list[] = [
                        "title"=>$v['title'],
                        "img"=>$v['thumb_url'],
                        "url"=>$v['url'],
                        "create_time"=>date("Y年m月d日",$val['content']['create_time']),
                    ];
                }
            }
        }
        //等于一次获取全部数值的大小，证明可能还有文章 所以还可以取
        if ($sub_wx_article['item_count']<$page_size){
            $status = [
                "no_more_data"=>true,
            ];
        }else{
            $status = [
                "no_more_data"=>false,
            ];
        }
        $status['list'] = $sub_wx_article_list;
        return $status;
    }
}
